package com.ywq.app.web.mvc.find;


import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.ywq.app.biz.ArtAuctionBiz;
import com.ywq.app.biz.ArtFindBiz;
import com.ywq.app.biz.ArtMadeBiz;
import com.ywq.app.biz.ArtPicBiz;
import com.ywq.app.biz.MemberBiz;
import com.ywq.app.domain.ArtArtist;
import com.ywq.app.domain.ArtArtistPic;
import com.ywq.app.domain.ArtClass;
import com.ywq.app.domain.ArtMap;
import com.ywq.app.domain.ArtOrders;
import com.ywq.app.domain.ArtPic;
import com.ywq.app.domain.FindSo;
import com.ywq.app.domain.Member;
import com.ywq.app.domain.MemberAddress;
import com.ywq.app.domain.MemberHas;
import com.ywq.app.domain.OnLineUserListener;
import com.ywq.app.domain.PicComment;
import com.ywq.app.domain.PwSchool;
import com.ywq.common.constant.Constant;
import com.ywq.common.constant.PageSize;
import com.ywq.common.exception.AppBusinessException;
import com.ywq.common.page.PageModel;



@Controller
public class FindController {
	private final static Logger logger = LoggerFactory.getLogger(FindController.class);
	@Autowired
	private ArtFindBiz artFindBiz;
	
	@Autowired
	private ArtPicBiz artPicBiz;
	@Autowired
	private ArtMadeBiz artMadeBiz;
	@Autowired
	private MemberBiz memberBiz;
	@Autowired
	private ArtAuctionBiz artAuctionBiz;
	
	@RequestMapping(value = "/map.htm")
	public String map(HttpServletRequest request, HttpServletResponse response) {
		return "/artOne/find/findMap";
	}
	@RequestMapping(value = "/found.htm")
	public String found(Integer page, FindSo findSo,HttpServletRequest request, HttpServletResponse response) {
		try {
			if (page == null) {
				page = 1;
			}
			FindSo findSoSession=null;
			if(findSo!=null){
				findSoSession= (FindSo)(request.getSession().getAttribute("findSoSession"));
				//精选
				if(findSo.getChoice()){
					request.setAttribute("choice", findSo.getChoice());
					request.setAttribute("bestLove", "false");
					request.setAttribute("bestMore", "false");
					request.setAttribute("bestNew", "false");
					//如果session为空，则实例化
					if(findSoSession==null){
						 findSoSession =new FindSo();
					}
					findSoSession.setChoice(true);
					findSoSession.setBestLove(false);
					findSoSession.setBestMore(false);
					findSoSession.setBestNew(false);
				}
				//最受欢迎
				if(findSo.getBestLove()){
					request.setAttribute("bestLove", findSo.getBestLove());
					request.setAttribute("choice", "false");
					request.setAttribute("bestMore", "false");
					request.setAttribute("bestNew", "false");
					//如果session为空，则实例化
					if(findSoSession==null){
						 findSoSession =new FindSo();
					}
					findSoSession.setBestLove(true);
					findSoSession.setChoice(false);
					findSoSession.setBestMore(false);
					findSoSession.setBestNew(false);
				}
				//最多浏览的
				if(findSo.getBestMore()){
					request.setAttribute("bestMore", findSo.getBestMore());
					request.setAttribute("choice", "false");
					request.setAttribute("bestLove", "false");
					request.setAttribute("bestNew", "false");
					//如果session为空，则实例化
					if(findSoSession==null){
						 findSoSession =new FindSo();
					}
					findSoSession.setBestMore(true);
					findSoSession.setChoice(false);
					findSoSession.setBestLove(false);
					findSoSession.setBestNew(false);
				}
				//最新上架的
				if(findSo.getBestNew()){
					request.setAttribute("bestNew", findSo.getBestNew());
					request.setAttribute("bestMore", "false");
					request.setAttribute("choice", "false");
					request.setAttribute("bestLove", "false");
					//如果session为空，则实例化
					if(findSoSession==null){
						 findSoSession =new FindSo();
					}
					findSoSession.setBestNew(true);
					findSoSession.setBestMore(false);
					findSoSession.setChoice(false);
					findSoSession.setBestLove(false);
				}
				if(!"".equals(findSo.getType())){
					if("find".equals(findSo.getType())){
						//创意领域
						//如果session为空，则实例化
						if(findSoSession==null){
							 findSoSession =new FindSo();
						}
						findSoSession.setFind(findSo.getId());
						ArtClass artClass =artPicBiz.getClassById(findSo.getId());
						findSoSession.setFindName(artClass.getName());
					}else if("price".equals(findSo.getType())){
						//价格范围
						//如果session为空，则实例化
						if(findSoSession==null){
							 findSoSession =new FindSo();
						}
						findSoSession.setPrice(findSo.getId());
						ArtClass artClass =artPicBiz.getClassById(findSo.getId());
						findSoSession.setPriceName(artClass.getName());
					}else if("tag".equals(findSo.getType())){
						//标签
						//如果session为空，则实例化
						if(findSoSession==null){
							 findSoSession =new FindSo();
						}
						findSoSession.setTag(findSo.getId());
						ArtClass artClass =artPicBiz.getClassById(findSo.getId());
						findSoSession.setTagName(artClass.getName());
					}else if("week".equals(findSo.getType())){
						//当周的
						//如果session为空，则实例化
						if(findSoSession==null){
							 findSoSession =new FindSo();
						}
						findSoSession.setWeek(true);
						findSoSession.setMonth(false);
						findSoSession.setStartDate(null);
						findSoSession.setEndDate(null);
					}else if("month".equals(findSo.getType())){
						//当月的
						//如果session为空，则实例化
						if(findSoSession==null){
							 findSoSession =new FindSo();
						}
						findSoSession.setMonth(true);
						findSoSession.setWeek(false);
						findSoSession.setStartDate(null);
						findSoSession.setEndDate(null);
					}
				}
				if(findSo.getStartDate()!=null && findSo.getEndDate()!=null){
					//如果session为空，则实例化
					if(findSoSession==null){
						 findSoSession =new FindSo();
					}
					findSoSession.setStartDate(findSo.getStartDate());
					findSoSession.setEndDate(findSo.getEndDate());
				}
			}
			PageModel  modelFindPic = artFindBiz.getFindPicList(page,findSoSession);
			request.setAttribute("modelFindPic", modelFindPic);
			//创意领域
			List<ArtClass> findList=artPicBiz.getChildById("0", Constant.PIC_FIND_CLASS);
			request.setAttribute("findList", findList);
			//材料
			List<ArtClass> materialList=artPicBiz.getChildById("0", Constant.PIC_MATERIAL_CLASS);
			request.setAttribute("materialList", materialList);
			//热门分类
			List<ArtClass> hotList=artPicBiz.getChildById("0", Constant.PIC_FIND_HOT);
			request.setAttribute("hotList", hotList);
			//专业分类
			List<ArtClass> profList=artPicBiz.getChildById("0", Constant.PIC_FIND_PROF);
			request.setAttribute("profList", profList);
			//尺寸
			List<ArtClass> sizeList=artPicBiz.getChildById("0", Constant.PIC_SIZE_CLASS);
			request.setAttribute("sizeList", sizeList);
			//年代
			List<ArtClass> yearsList=artPicBiz.getChildById("0", Constant.PIC_YEARS_CLASS);
			request.setAttribute("yearsList", yearsList);
			//环境
			List<ArtClass> groundList=artPicBiz.getChildById("0", Constant.PIC_GROUND_CLASS);
			request.setAttribute("groundList", groundList);
			//用途
			List<ArtClass> useList=artPicBiz.getChildById("0", Constant.PIC_USE_CLASS);
			request.setAttribute("useList", useList);
			//价格
			List<ArtClass> priceList=artPicBiz.getChildById("0", Constant.PIC_PRICE_CLASS);
			request.setAttribute("priceList", priceList);
			//标签
			List<ArtClass> tagList=artPicBiz.getChildById("0", Constant.PIC_TAG_CLASS);
			request.setAttribute("tagList", tagList);
			if(findSoSession!=null){
				request.getSession(true).setAttribute("findSoSession", findSoSession);
			}
			
		} catch (AppBusinessException e) {
			e.printStackTrace();
		}
		return "/artOne/find/find";
	}
	@RequestMapping(value = "/deleteSave.htm")
	public String deleteSave(HttpServletRequest request, HttpServletResponse response) {
		try { 
			response.setContentType("text/html; charset=UTF-8");
			PrintWriter out = response.getWriter();
				request.getSession().removeAttribute("findSoSession");
				request.getSession().removeAttribute("printSoSession");
				request.getSession().removeAttribute("profSoSession");
				out.print("true");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	@RequestMapping(value = "/fartist.htm")
	public String findArtist(Integer page,String province,String school,HttpServletRequest request, HttpServletResponse response) {
		//取得首页内容
		//查询所有作者的作品(第一幅图)
		try {
			if (page == null) {
				page = 1;
			}
			
			PageModel  modelFindArtist = artFindBiz.getFindArtistList(page,province,school);
			request.setAttribute("modelFindArtist", modelFindArtist);
			//创意领域
			List<ArtClass> findList=artPicBiz.getChildById("0", Constant.PIC_FIND_CLASS);
			request.setAttribute("findList", findList);
			//材料
			List<ArtClass> materialList=artPicBiz.getChildById("0", Constant.PIC_MATERIAL_CLASS);
			request.setAttribute("materialList", materialList);
			//热门分类
			List<ArtClass> hotList=artPicBiz.getChildById("0", Constant.PIC_FIND_HOT);
			request.setAttribute("hotList", hotList);
			//专业分类
			List<ArtClass> profList=artPicBiz.getChildById("0", Constant.PIC_FIND_PROF);
			request.setAttribute("profList", profList);
			//尺寸
			List<ArtClass> sizeList=artPicBiz.getChildById("0", Constant.PIC_SIZE_CLASS);
			request.setAttribute("sizeList", sizeList);
			//年代
			List<ArtClass> yearsList=artPicBiz.getChildById("0", Constant.PIC_YEARS_CLASS);
			request.setAttribute("yearsList", yearsList);
			//环境
			List<ArtClass> groundList=artPicBiz.getChildById("0", Constant.PIC_GROUND_CLASS);
			request.setAttribute("groundList", groundList);
			//用途
			List<ArtClass> useList=artPicBiz.getChildById("0", Constant.PIC_USE_CLASS);
			request.setAttribute("useList", useList);
			//价格
			List<ArtClass> priceList=artPicBiz.getChildById("0", Constant.PIC_PRICE_CLASS);
			request.setAttribute("priceList", priceList);
			//标签
			List<ArtClass> tagList=artPicBiz.getChildById("0", Constant.PIC_TAG_CLASS);
			request.setAttribute("tagList", tagList);
		} catch (AppBusinessException e) {
			e.printStackTrace();
			if (logger.isErrorEnabled()) {
				logger.error("findArtist failure.", e);
			}
		}
		return "/artOne/find/findArtist";
	}
	//地图人数
	@RequestMapping(value = "/mapNum.htm")
	public String mapNum(HttpServletRequest request, HttpServletResponse response) {
		try { 
			response.setContentType("text/html; charset=UTF-8");
			PrintWriter out = response.getWriter();
			List<ArtMap> mapCity = artFindBiz.getNumByCtiy();
			out.print(JSONArray.fromObject(mapCity));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	//新增评论
	@RequestMapping(value = "/saveComment.htm")
	public String addComment(PicComment picComment, HttpServletRequest request, HttpServletResponse response) {
		OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
		try { 
			response.setContentType("text/html; charset=UTF-8");
			PrintWriter out = response.getWriter();
			if(onLineUserListener.getMember()!=null){
				picComment.setMember(onLineUserListener.getMember().getId());
				artFindBiz.insertComment(picComment);
				out.print("true");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	//列表页面
	@RequestMapping(value = "/cList.htm")
	public String getFindCommentModelByPicId(Integer page,String picId,HttpServletRequest request, HttpServletResponse response) {
		try {
			if (page == null) {
				page = 1;
			}
			PageModel  commentModel = artFindBiz.getFindCommentModelByPicId(page, picId);
			request.setAttribute("commentModel", commentModel);
			request.setAttribute("picId", picId);
		} catch (AppBusinessException e) {
			e.printStackTrace();
		}
		return "/artOne/find/commentModel";
	}
	//作品详情
	@RequestMapping(value = "/fpic.htm")
	public String getFindPicByPicId(String picId,HttpServletRequest request, HttpServletResponse response) {
		try {
			//评论
			List<PicComment>  commentList = artFindBiz.getFindCommentByPicId(picId);
			//
			ArtPic artPic= artPicBiz.getArtPic(picId);
			request.setAttribute("artPic", artPic);
			request.setAttribute("commentList", commentList);
		} catch (AppBusinessException e) {
			e.printStackTrace();
		}
		return "/artOne/find/fpic";
	}
	//分类页面一级
	@RequestMapping(value = "/print.htm")
	public String getPrint(Integer page, FindSo findSo ,HttpServletRequest request, HttpServletResponse response) {
		try {
			if (page == null) {
				page = 1;
			}
			ArtClass artClass =artPicBiz.getClassById(findSo.getHot());
			request.setAttribute("artClass",artClass);
			PageModel  modelFindPic = artFindBiz.getPrintPicList(page,findSo);
			List<ArtClass> childrenList=artPicBiz.getChildById(findSo.getHot(),Constant.PIC_FIND_HOT);
			request.setAttribute("childrenList", childrenList);
			request.setAttribute("modelFindPic", modelFindPic);
			request.setAttribute("printId", findSo.getHot());
			//尺寸
			List<ArtClass> sizeList=artPicBiz.getChildById("0", Constant.PIC_SIZE_CLASS);
			request.setAttribute("sizeList", sizeList);
			//价格
			List<ArtClass> priceList=artPicBiz.getChildById("0", Constant.PIC_PRICE_CLASS);
			request.setAttribute("priceList", priceList);
			//环境
			List<ArtClass> groundList=artPicBiz.getChildById("0", Constant.PIC_GROUND_CLASS);
			request.setAttribute("groundList", groundList);
			//用途
			List<ArtClass> useList=artPicBiz.getChildById("0", Constant.PIC_USE_CLASS);
			request.setAttribute("useList", useList);
		} catch (AppBusinessException e) {
			e.printStackTrace();
		}
		return "/artOne/find/print";
	}
	//分类页面二级
	@RequestMapping(value = "/prints.htm")
	public String getPrints(Integer page, FindSo findSo,String yhot,HttpServletRequest request, HttpServletResponse response) {
		try {
			if (page == null) {
				page = 1;
			}
			FindSo printSoSession=null;
			if(findSo!=null){
				printSoSession= (FindSo)(request.getSession().getAttribute("printSoSession"));
				//用途
				if(!"".equals(findSo.getUse()) && findSo.getUse()!=null){
					if(printSoSession==null){
						printSoSession =new FindSo();
					}
					printSoSession.setUse(findSo.getUse());
					ArtClass artClass =artPicBiz.getClassById(findSo.getUse());
					printSoSession.setUseName(artClass.getName());
				}
				if("1".equals(yhot)){
					if(printSoSession==null){
						printSoSession =new FindSo();
						printSoSession.setHot(findSo.getHot());
						request.setAttribute("yhot", yhot);
					}
				}
				//尺寸
				if(!"".equals(findSo.getSize()) && findSo.getSize()!=null){
					if(printSoSession==null){
						printSoSession =new FindSo();
					}
					printSoSession.setSize(findSo.getSize());
					ArtClass artClass =artPicBiz.getClassById(findSo.getSize());
					printSoSession.setSizeName(artClass.getName());
				}
				//环境
				if(!"".equals(findSo.getGround()) && findSo.getGround()!=null){
					if(printSoSession==null){
						printSoSession =new FindSo();
					}
					printSoSession.setGround(findSo.getGround());
					ArtClass artClass =artPicBiz.getClassById(findSo.getGround());
					printSoSession.setGroundName(artClass.getName());
				}
				if(!"".equals(findSo.getPrice()) && findSo.getPrice()!=null){
					if(printSoSession==null){
						printSoSession =new FindSo();
					}
					printSoSession.setPrice(findSo.getPrice());
					ArtClass artClass =artPicBiz.getClassById(findSo.getPrice());
					printSoSession.setPriceName(artClass.getName());
				}
				
			}
			if(printSoSession==null){
				PageModel  modelFindPic = artFindBiz.getPrintsPicList(page,findSo);
				request.setAttribute("modelFindPic", modelFindPic);
			}else{
				PageModel  modelFindPic = artFindBiz.getPrintsPicList(page,printSoSession);
				request.setAttribute("modelFindPic", modelFindPic);
			}
			
			//查询分类
			ArtClass artClass =artPicBiz.getClassById(findSo.getHot());
			if(artClass!=null){
				//同级分类
				List<ArtClass> childrenList=artPicBiz.getChildById(artClass.getParent(),Constant.PIC_FIND_HOT);
				request.setAttribute("childrenList", childrenList);
			}
			request.setAttribute("hotId", findSo.getHot());
			ArtClass hotClass =artPicBiz.getClassById(findSo.getHot());
			request.setAttribute("hotName",hotClass.getName());
			request.setAttribute("artClass", artClass);
			//尺寸
			List<ArtClass> sizeList=artPicBiz.getChildById("0", Constant.PIC_SIZE_CLASS);
			request.setAttribute("sizeList", sizeList);
			//价格
			List<ArtClass> priceList=artPicBiz.getChildById("0", Constant.PIC_PRICE_CLASS);
			request.setAttribute("priceList", priceList);
			//环境
			List<ArtClass> groundList=artPicBiz.getChildById("0", Constant.PIC_GROUND_CLASS);
			request.setAttribute("groundList", groundList);
			//用途
			List<ArtClass> useList=artPicBiz.getChildById("0", Constant.PIC_USE_CLASS);
			request.setAttribute("useList", useList);
			if(printSoSession!=null){
				request.getSession(true).setAttribute("printSoSession", printSoSession);
			}
		} catch (AppBusinessException e) {
			e.printStackTrace();
		}
		return "/artOne/find/printc";
	}
	@RequestMapping(value = "/prof.htm")
	public String getprof(Integer page, FindSo findSo,HttpServletRequest request, HttpServletResponse response) {
		try {
			if (page == null) {
				page = 1;
			}
			PageModel  modelFindPic = artFindBiz.getPrintPicList(page,findSo);
			//专业分类
			List<ArtClass> profList=artPicBiz.getChildById(findSo.getProf(),Constant.PIC_FIND_PROF);
			request.setAttribute("profList", profList);
			request.setAttribute("childrenList", profList);
			request.setAttribute("modelFindPic", modelFindPic);
			request.setAttribute("profId", findSo.getProf());
			ArtClass artClass =artPicBiz.getClassById(findSo.getProf());
			request.setAttribute("artClass",artClass);
			//尺寸
			List<ArtClass> sizeList=artPicBiz.getChildById("0", Constant.PIC_SIZE_CLASS);
			request.setAttribute("sizeList", sizeList);
			//价格
			List<ArtClass> priceList=artPicBiz.getChildById("0", Constant.PIC_PRICE_CLASS);
			request.setAttribute("priceList", priceList);
			//环境
			List<ArtClass> groundList=artPicBiz.getChildById("0", Constant.PIC_GROUND_CLASS);
			request.setAttribute("groundList", groundList);
			//用途
			List<ArtClass> useList=artPicBiz.getChildById("0", Constant.PIC_USE_CLASS);
			request.setAttribute("useList", useList);
		} catch (AppBusinessException e) {
			e.printStackTrace();
		}
		return "/artOne/find/prof";
	}
	//专业二级分类
	@RequestMapping(value = "/profs.htm")
	public String getProfs(Integer page, FindSo findSo,String yprof,HttpServletRequest request, HttpServletResponse response) {
		try {
			if (page == null) {
				page = 1;
			}
			FindSo profSoSession=null;
			if(findSo!=null){
				profSoSession= (FindSo)(request.getSession().getAttribute("profSoSession"));
				//用途
				if(!"".equals(findSo.getUse()) && findSo.getUse()!=null){
					if(profSoSession==null){
						profSoSession =new FindSo();
					}
					profSoSession.setUse(findSo.getUse());
					ArtClass artClass =artPicBiz.getClassById(findSo.getUse());
					profSoSession.setUseName(artClass.getName());
				}
				if("1".equals(yprof)){
					if(profSoSession==null){
						profSoSession =new FindSo();
						profSoSession.setProf(findSo.getProf());
						request.setAttribute("yprof", yprof);
					}
				}
				//尺寸
				if(!"".equals(findSo.getSize()) && findSo.getSize()!=null){
					if(profSoSession==null){
						profSoSession =new FindSo();
						
					}
					profSoSession.setSize(findSo.getSize());
					ArtClass artClass =artPicBiz.getClassById(findSo.getSize());
					profSoSession.setSizeName(artClass.getName());
				}
				//环境
				if(!"".equals(findSo.getGround()) && findSo.getGround()!=null){
					if(profSoSession==null){
						profSoSession =new FindSo();
					}
					profSoSession.setGround(findSo.getGround());
					ArtClass artClass =artPicBiz.getClassById(findSo.getGround());
					profSoSession.setGroundName(artClass.getName());
				}
				if(!"".equals(findSo.getPrice()) && findSo.getPrice()!=null){
					if(profSoSession==null){
						profSoSession =new FindSo();
					}
					profSoSession.setPrice(findSo.getPrice());
					ArtClass artClass =artPicBiz.getClassById(findSo.getPrice());
					profSoSession.setPriceName(artClass.getName());
				}
				
			}
			if(profSoSession==null){
				PageModel  modelFindPic = artFindBiz.getPrintsPicList(page,findSo);
				request.setAttribute("modelFindPic", modelFindPic);
			}else{
				PageModel  modelFindPic = artFindBiz.getPrintsPicList(page,profSoSession);
				request.setAttribute("modelFindPic", modelFindPic);
			}
			
			//查询分类
			ArtClass artClass =artPicBiz.getClassById(findSo.getProf());
			if(artClass!=null){
				//同级分类
				List<ArtClass> profList=artPicBiz.getChildById(artClass.getParent(),Constant.PIC_FIND_PROF);
				request.setAttribute("profList", profList);
			}
			
			request.setAttribute("profId", findSo.getProf());
			ArtClass profClass =artPicBiz.getClassById(findSo.getProf());
			request.setAttribute("profName",profClass.getName());
			request.setAttribute("artClass", artClass);
			
			//尺寸
			List<ArtClass> sizeList=artPicBiz.getChildById("0", Constant.PIC_SIZE_CLASS);
			request.setAttribute("sizeList", sizeList);
			//价格
			List<ArtClass> priceList=artPicBiz.getChildById("0", Constant.PIC_PRICE_CLASS);
			request.setAttribute("priceList", priceList);
			//环境
			List<ArtClass> groundList=artPicBiz.getChildById("0", Constant.PIC_GROUND_CLASS);
			request.setAttribute("groundList", groundList);
			//用途
			List<ArtClass> useList=artPicBiz.getChildById("0", Constant.PIC_USE_CLASS);
			request.setAttribute("useList", useList);
			if(profSoSession!=null){
				request.getSession(true).setAttribute("profSoSession", profSoSession);
			}
		} catch (AppBusinessException e) {
			e.printStackTrace();
		}
		return "/artOne/find/profs";
	}
	//作品详情
	@RequestMapping(value = "/fart.htm")
	public String getFart( String id,HttpServletRequest request, HttpServletResponse response) {
		try {
			if(id==null || "".equals(id)){
				return null;
			}
			ArtPic artPic =artPicBiz.getArtPic(id);
			//浏览数+1
			ArtPic lookNumPic=new ArtPic();
			lookNumPic.setIdentifier(id);
			lookNumPic.setViewAmount(artPic.getViewAmount()+1);
			artPicBiz.updatePicViewAmount(lookNumPic);
			//尺寸
			ArtClass sizeClass=artPicBiz.getClassById(artPic.getArtSize());
			if(sizeClass!=null){
				artPic.setArtSizeName(sizeClass.getName());
			}
			//材料
			ArtClass materialClass=artPicBiz.getClassById(artPic.getMaterial());
			if(materialClass!=null){
				artPic.setMaterialName(materialClass.getName());
			}
			//用途
			ArtClass useClass=artPicBiz.getClassById(artPic.getArtuse());
			if(useClass!=null){
				artPic.setUseName(useClass.getName());
			}
			//环境
			ArtClass groundClass=artPicBiz.getClassById(artPic.getGround());
			if(groundClass!=null){
				artPic.setGroundName(groundClass.getName());
			}
			//范围
			ArtClass rangeClass=artPicBiz.getClassById(artPic.getArtrange());
			if(rangeClass!=null){
				artPic.setRangeName(rangeClass.getName());
			}
			//年代
			ArtClass yearsClass=artPicBiz.getClassById(artPic.getYears());
			if(yearsClass!=null){
				artPic.setYearsName(yearsClass.getName());
			}
			//标签名
			ArtClass tagClass=artPicBiz.getClassById(artPic.getTag());
			if(tagClass!=null){
				artPic.setTagName(tagClass.getName());
			}
			//分类
			ArtClass artClass=artPicBiz.getClassById(artPic.getArtClass());
			
			if(artClass!=null){
					artPic.setArtClassName(artClass.getName());
			}
			request.setAttribute("artPic", artPic);
			//作者
			ArtArtistPic artArtistPic =artMadeBiz.getArtArtistPicByPicId(id);
			ArtArtist artArtist =artMadeBiz.getArtist(artArtistPic.getArtistId());
			if(artArtist.getSchoolid()!="" && !"".equals(artArtist.getSchoolid())){
				PwSchool pwSchool =artFindBiz.getSchool(artArtist.getSchoolid());
				artArtist.setSchoolName(pwSchool.getName());
			}
			request.setAttribute("artArtist", artArtist);
			//查询作者的3个作品
			List<ArtArtistPic> artistPicList=artMadeBiz.getArtistPicList(artArtistPic.getArtistId());
			//查询该作者的作品总数
			int allPicNumByArtistId=artMadeBiz.getAllPicNumByArtistId(artArtistPic.getArtistId());
			request.setAttribute("allPicNumByArtistId", allPicNumByArtistId);
			request.setAttribute("artistPicList", artistPicList);
			//查询4个作品 同类
			List<ArtPic> sameClassPic =artPicBiz.getSameClassPicList(artPic.getArtClass());
			request.setAttribute("sameClassPic", sameClassPic);
			//作品的评论
			List<PicComment> commentList=artFindBiz.getFindCommentByPicId(id);
			request.setAttribute("commentList", commentList);
			
			int commentCount= artFindBiz.getFindCommentCountByPicId(id);
			request.setAttribute("commentCount", commentCount);
			//查询某一画家所有作品的访问数，喜欢数
			ArtArtist allCount =artFindBiz.getAllCountByArtistId(artArtist.getId());
			request.setAttribute("allCount", allCount);
		} catch (AppBusinessException e) {
			e.printStackTrace();
		}
		return "/artOne/find/fart";
	}
	//艺术家
	@RequestMapping(value = "/fartistInfo.htm")
	public String getFartist(String artistId,Integer page,String classId,HttpServletRequest request, HttpServletResponse response) {
			if (page == null) {
				page = 1;
			}
		try {
			ArtArtist artArtist = artMadeBiz.getArtist(artistId);
			if(artArtist.getSchoolid()!="" && !"".equals(artArtist.getSchoolid())){
				PwSchool pwSchool =artFindBiz.getSchool(artArtist.getSchoolid());
				artArtist.setSchoolName(pwSchool.getName());
			}	
			//艺术家作品
			if (classId == null) {
				PageModel pageModel = artMadeBiz.getArtistPicListForMisc(page,artistId,12);
				request.setAttribute("pageModel", pageModel);
			}else{
				//classId是父类
				PageModel  pageModel = artMadeBiz.getArtistPicListForArtist(page,artistId,12,classId);
				request.setAttribute("pageModel", pageModel);
			}
			request.setAttribute("artArtist", artArtist);
			request.setAttribute("artistId", artistId);
			ArtArtist allCount =artFindBiz.getAllCountByArtistId(artArtist.getId());
			request.setAttribute("allCount", allCount);
			//创意领域
			List<ArtClass> findList=artPicBiz.getChildById("0", Constant.PIC_FIND_CLASS);
			request.setAttribute("findList", findList);
		} catch (AppBusinessException e) {
			e.printStackTrace();
		}
	
		return "/artOne/find/fartist";
	}
	//购买
	@RequestMapping(value = "/buyArt.htm")
	public String getBuyArt(String id,HttpServletRequest request, HttpServletResponse response) {
		OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
		if (onLineUserListener != null) {
			try {
				List<MemberAddress> addressList =memberBiz.getAddressListByMemberId(onLineUserListener.getMember().getId());
				ArtPic artPic =artPicBiz.getArtPic(id);
				//尺寸
				ArtClass sizeClass=artPicBiz.getClassById(artPic.getArtSize());
				if(sizeClass!=null){
					artPic.setArtSizeName(sizeClass.getName());
				}
				//材料
				ArtClass materialClass=artPicBiz.getClassById(artPic.getMaterial());
				if(materialClass!=null){
					artPic.setMaterialName(materialClass.getName());
				}
				//用途
				ArtClass useClass=artPicBiz.getClassById(artPic.getArtuse());
				if(useClass!=null){
					artPic.setUseName(useClass.getName());
				}
				//环境
				ArtClass groundClass=artPicBiz.getClassById(artPic.getGround());
				if(groundClass!=null){
					artPic.setGroundName(groundClass.getName());
				}
				//范围
				ArtClass rangeClass=artPicBiz.getClassById(artPic.getArtrange());
				if(rangeClass!=null){
					artPic.setRangeName(rangeClass.getName());
				}
				//年代
				ArtClass yearsClass=artPicBiz.getClassById(artPic.getYears());
				if(yearsClass!=null){
					artPic.setYearsName(yearsClass.getName());
				}
				//标签名
				ArtClass tagClass=artPicBiz.getClassById(artPic.getTag());
				if(tagClass!=null){
					artPic.setTagName(tagClass.getName());
				}
				//分类
				ArtClass artClass=artPicBiz.getClassById(artPic.getArtClass());
				
				if(artClass!=null){
						artPic.setArtClassName(artClass.getName());
				}
				request.setAttribute("addressList", addressList);
				request.setAttribute("id", id);
				request.setAttribute("artPic", artPic);
			} catch (AppBusinessException e) {
				e.printStackTrace();
			}
		} else {
			return null;
		}
		return "/artOne/find/buyStepOne";
	}
	//下单
	@RequestMapping(value = "/addFindOrder.htm")
	public String addFindOrder(String picId,String address,HttpServletRequest request, HttpServletResponse response) {
		OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
		Map<String,Object> isJoin = new HashMap<String,Object>();
		
		try { 
			response.setContentType("text/html; charset=UTF-8");
			PrintWriter out = response.getWriter();
			if(onLineUserListener.getMember()!=null){
				Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
				MemberAddress artAddress =memberBiz.getAddressByaId(address);
				if(member!=null && artAddress !=null){
					ArtOrders artOrder=new ArtOrders();
					//地址
					artOrder.setAddress(artAddress.getAddress());
					artOrder.setAddressName(artAddress.getAddressName());
					artOrder.setCity(artAddress.getCity());
					artOrder.setCounty(artAddress.getCounty());
					artOrder.setGoodTime(artAddress.getGoodTime());
					artOrder.setPhone(artAddress.getPhone());
					artOrder.setProvince(artAddress.getProvince());
					artOrder.setTelphone(artAddress.getTelphone());
					artOrder.setZipcode(artAddress.getZipcode());
					ArtPic artPic =artPicBiz.getArtPic(picId);
					if(artPic.getIsForward()){
						isJoin.put("date", "false");
						out.print(JSONObject.fromObject(isJoin));
					}else {
						if(artPic!=null && !"".equals(artPic.getPriceLow())){
							if(artPic.getPriceLow()>0 ){
								artOrder.setSucPrice(artPic.getPriceLow());
							}else{
								artOrder.setSucPrice(artPic.getPrice());
							}
						}
						artOrder.setType(PageSize.ARTIST_FIND);
						artOrder.setTypeId(picId);
						artOrder.setMemberId(member.getId());
						artOrder.setRemark("购买作品："+artPic.getTitle());
						artOrder.setTitle("购买作品："+artPic.getTitle());
						String orderId=artAuctionBiz.insertFindArtOrders(artOrder);
						isJoin.put("orderId", orderId);
						isJoin.put("date", "true");
						out.print(JSONObject.fromObject(isJoin));
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	//付款
	@RequestMapping(value = "/payArt.htm")
	public String getPayArt(String orderId,HttpServletRequest request, HttpServletResponse response) {
		OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
		if (onLineUserListener != null) {
			
			try {
				ArtOrders artOrder =memberBiz.getOrdersById(orderId);
				if(artOrder!=null){
					//
					ArtPic artPic =artPicBiz.getArtPic(artOrder.getTypeId());
					//尺寸
					ArtClass sizeClass=artPicBiz.getClassById(artPic.getArtSize());
					if(sizeClass!=null){
						artPic.setArtSizeName(sizeClass.getName());
					}
					//材料
					ArtClass materialClass=artPicBiz.getClassById(artPic.getMaterial());
					if(materialClass!=null){
						artPic.setMaterialName(materialClass.getName());
					}
					//用途
					ArtClass useClass=artPicBiz.getClassById(artPic.getArtuse());
					if(useClass!=null){
						artPic.setUseName(useClass.getName());
					}
					//环境
					ArtClass groundClass=artPicBiz.getClassById(artPic.getGround());
					if(groundClass!=null){
						artPic.setGroundName(groundClass.getName());
					}
					//范围
					ArtClass rangeClass=artPicBiz.getClassById(artPic.getArtrange());
					if(rangeClass!=null){
						artPic.setRangeName(rangeClass.getName());
					}
					//年代
					ArtClass yearsClass=artPicBiz.getClassById(artPic.getYears());
					if(yearsClass!=null){
						artPic.setYearsName(yearsClass.getName());
					}
					//标签名
					ArtClass tagClass=artPicBiz.getClassById(artPic.getTag());
					if(tagClass!=null){
						artPic.setTagName(tagClass.getName());
					}
					//分类
					ArtClass artClass=artPicBiz.getClassById(artPic.getArtClass());
					
					if(artClass!=null){
							artPic.setArtClassName(artClass.getName());
					}
					request.setAttribute("artPic", artPic);
					request.setAttribute("artOrder", artOrder);
					//request.setAttribute("artAddress", artAddress);
				}
			} catch (AppBusinessException e) {
				e.printStackTrace();
			}
		} else {
			return null;
		}
		return "/artOne/find/buyStepTwo";
	}
	@RequestMapping(value = "/likeArtArtist.htm", method = RequestMethod.GET)
	public String artHas(String artistId,HttpServletRequest request,HttpServletResponse response) throws IOException {
		response.setContentType("text/html; charset=UTF-8");
		PrintWriter pw = null;
		try {
			OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
			if(onLineUserListener.getMember()!=null){
				//
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("ownerId", artistId);
				map.put("memberId", onLineUserListener.getMember().getId());
				map.put("owner", "like");
				map.put("type", "artist");
				List<MemberHas> list = memberBiz.getHasList(map);
				
				if (list != null && list.size() > 0) {
					pw = response.getWriter();
					pw.print("alreadyLove");
				} else {
					MemberHas memberHas =new MemberHas();
					memberHas.setMemberId(onLineUserListener.getMember().getId());
					memberHas.setOwnerId(artistId);
					memberHas.setOwner("like"); //look love keep like
					memberHas.setType("artist"); //发现、拍卖、展览馆 艺术家
					memberBiz.insertMemberHas(memberHas);
					//增加作品 look love keep 数
					ArtArtist artArtist =artMadeBiz.getArtist(artistId);
					ArtArtist artArtistNew =new ArtArtist();
					artArtistNew.setId(artistId);
					artArtistNew.setLikeAmount(artArtist.getLikeAmount()+1);
					artMadeBiz.updateArtist(artArtistNew);
					
					pw = response.getWriter();
					pw.print("likeSuccess");
				}
			}else{
				pw = response.getWriter();
				pw.print("error");
			}
		} catch (Exception e) {
			pw = response.getWriter();
			pw.print("error");
			if (logger.isErrorEnabled()) {
				logger.error("auction failure.", e);
			}
		}
		return null;
		}
	//联系学校
	@RequestMapping(value = "/school.htm")
	public String lxCompany(HttpServletRequest request, HttpServletResponse response,
			String name) throws IOException {
		try {
			response.setContentType("text/html; charset=UTF-8"); 
        	PrintWriter out = response.getWriter();
			List<PwSchool> companys = artFindBiz.getCompanyByName(name);
			out.print(JSONArray.fromObject(companys));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
